package tyx.study.jsp.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import tyx.study.jsp.javabean.Emp;
import tyx.study.jsp.service.IEmpService;
import tyx.study.jsp.service.impl.EmpServiceImp;
@WebServlet("/findEmp")
public class FindEmpServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset=utf-8");
		String enoStr=req.getParameter("eno");
		Integer eno=0;
		if (enoStr!=null) {
			eno=Integer.parseInt(enoStr);
		}
		if (eno!=0) {
			IEmpService empService=new EmpServiceImp();
			Emp emp=empService.findByEno(eno);
			if (emp!=null) {
				req.setAttribute("emp", emp);
			}
			req.getRequestDispatcher("showEmp.jsp").forward(req, resp);
		}
		
	}
}
